package org.strangewt.demo.composit;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.strangewt.demo.testdata.Person;
import org.strangewt.demo.testdata.Project;
import org.strangewt.jface.viewers.CompositeViewer;
import org.strangewt.widgets.CompositeBase;

public class CompositeCompositeViewer extends CompositeBase implements SelectionListener {

	private CompositeViewer compViewer;
	
	private Button btPerson;
	private Button btProject;
	
	
	public CompositeCompositeViewer(Composite parent, int style) {
		super(parent, style);
		
		createControl(this);
	}

	private void createControl(Composite parent) {
		
		setLayout(new GridLayout());

		compViewer = new CompositeViewer(parent, SWT.BORDER);
		compViewer.setCompositeProvider(new CompositeProviderPersonProject());
		compViewer.setLayoutData(createGridDataForInputFields(150, 150));
		
		btPerson = createButton(parent, "Person", this);
		btProject = createButton(parent, "Project", this);
	}

	// SelectionListener ////////////////////////////

	@Override
	public void widgetSelected(SelectionEvent e) {
		if(e.widget == btPerson) {
			compViewer.setInput(new Person("strange", "optics", 35, 'M'));
		}
		if(e.widget == btProject) {
			compViewer.setInput(new Project("Strangewt", "More programming convinience!"));
		}
	}

	@Override
	public void widgetDefaultSelected(SelectionEvent e) {
		
	}
	
}
